<?php

class recupera_info extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    // Recupera una listado para un grid de ExtJs
    function getList1() {
        $ssql = "SELECT * FROM presidents pr, parties pa WHERE pr.IDparty = pa.IDparty";

        $query = $this->db->query($ssql);
        $resultado = $query->result_array();
        $numrows = $query->num_rows();


        if ($numrows > 0) {

            foreach ($query->result_array() as $row) {
                $row['tookoffice'] = codeDate($row['tookoffice']);
                $row['leftoffice'] = codeDate($row['leftoffice']);
                $arr[] = $row;
            }
            $jsonresult = json_encode($arr);
//            echo '({"total":"' . $numrows . '","results":' . $jsonresult . '})';
            return '({"total":"' . $numrows . '","results":' . $jsonresult . '})';
        } else {
//            echo '({"total":"0", "results":""})';
            return '({"total":"0", "results":""})';
        }
    }

    function getList() {
        $ssql = "SELECT name, email, phone FROM simsons";

        $query = $this->db->query($ssql);
        $resultado = $query->result_array();
        $numrows = $query->num_rows();

        $arr = array();

        foreach ($query->result_array() as $row) {
//                $row['tookoffice'] = codeDate($row['tookoffice']);
//                $row['leftoffice'] = codeDate($row['leftoffice']);
            $arr[] = $row;
        }
        $jsonresult = json_encode($arr);
        return '{succes:true,results:' . $numrows . ',rows:' . json_encode($arr) . '}';
    }

    // Encodes a YYYY-MM-DD into a MM-DD-YYYY string
    function codeDate($date) {
        $tab = explode("-", $date);
        $r = $tab[1] . "/" . $tab[2] . "/" . $tab[0];
        return $r;
    }

}

?>
